package bb.lanxing.util;

import android.content.Context;
import bb.lanxing.R;
import bb.lanxing.model.database.IWorkout;
import bb.lanxing.model.database.Workout;

import java.util.Calendar;

public class WorkoutTitleUtil {
    public static String buildDefaultTitlePrefix(Context context, long vStartTime) {
        String format = DateUtil.format(vStartTime, 1);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(vStartTime);
        int i = calendar.get(11);
        if (i < 6) {
            return format + " " + context.getString(R.string.before_dawn) + " ";
        } else if (i < 12) {
            return format + " " + context.getString(R.string.morning) + " ";
        } else if (i < 18) {
            return format + " " + context.getString(R.string.afternoon) + " ";
        } else {
            return format + " " + context.getString(R.string.night) + " ";
        }
    }

    public static String buildDefaultTitleType(Context context, int vSportType) {
        switch (vSportType) {
            case Workout.TYPE_OTHER -> {
                return context.getResources().getString(R.string.other_sport);
            }
            case Workout.TYPE_WALKING -> {
                return context.getResources().getString(R.string.walking);
            }
            case Workout.TYPE_RUNNING -> {
                return context.getResources().getString(R.string.running);
            }
            case Workout.TYPE_SWIMMING -> {
                return context.getResources().getString(R.string.swimming);
            }
            case Workout.TYPE_SKIING -> {
                return context.getResources().getString(R.string.skiing);
            }
            case Workout.TYPE_TRAINING -> {
                return context.getResources().getString(R.string.training);
            }
            case Workout.TYPE_INDOOR_BIKE -> {
                return context.getResources().getString(R.string.ftms_indoor_bike);
            }
            case Workout.TYPE_BIKE_TRAINER -> {
                return context.getResources().getString(R.string.device_biketrainer_title);
            }
            case Workout.TYPE_ROWER -> {
                return context.getResources().getString(R.string.device_rower_title);
            }
            case Workout.TYPE_CROSS_TRAINER -> {
                return context.getResources().getString(R.string.ftms_crosstrainer);
            }
            default -> {
                return context.getResources().getString(R.string.cycling);
            }
        }
    }

    public static String buildWorkoutDefaultTitle(Context context, IWorkout iWorkout) {
        String buildDefaultTitlePrefix = iWorkout.getStartTime() > 0 ? buildDefaultTitlePrefix(context, iWorkout.getStartTime()) : "";
        String buildDefaultTitleType = buildDefaultTitleType(context, iWorkout.getSport());
        return buildDefaultTitlePrefix + buildDefaultTitleType;
    }
}
